import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../provide/riverpod_provider.dart';
import 'package:rabbit_mobile/main.dart'; // 引入 themeModeProvider

class ChangeThemeWidget extends ConsumerWidget {
  const ChangeThemeWidget({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final themeMode = ref.watch(themeModeProvider);

    return Scaffold(
      appBar: AppBar(title: const Text('主题切换 Demo')),
      body: Center(
        child: ElevatedButton.icon(
          icon: Icon(
            themeMode == ThemeMode.dark ? Icons.dark_mode : Icons.light_mode,
          ),
          label: Text('切换主题'),
          onPressed: () {
            final newTheme = themeMode == ThemeMode.dark ? ThemeMode.light : ThemeMode.dark;
            ref.read(themeModeProvider.notifier).state = newTheme;
          },
        ),
      ),
    );
  }
}
